﻿using System;

using YAMM;
using YAMM.PlugIn;

namespace PluginAmazon
{
    public class Plugin : IPlugin
    {
        //ServiceProvider serviceProvider = null;

        //#region IPlugin Members

        //public string Name
        //{
        //    get { return "Amazon Plugin"; }
        //}

        ///// <summary>
        ///// Gets the GUID of the plugin.
        ///// </summary>
        ///// <value>The GUID.</value>
        //public Guid Guid
        //{
        //    get
        //    {
        //        return new Guid("5EF2E4A4-35A6-492c-A2C8-DF74F6F3D644");
        //    }
        //}

        //public string Version
        //{
        //    get { return "0.0.0.1a"; }
        //}

        //public string Author
        //{
        //    get { return "Frank Weißenborn"; }
        //}

        //public void Show()
        //{
        //    Main mn = new Main();
        //    mn.Show();
        //}

        //public void Configure()
        //{
        //    Configure config = new Configure();
        //    config.Show();
        //}

        //public bool canReceive(Type t)
        //{
        //    if (t == typeof(YAMM.DataTypes.MovieDT)) return true;
        //    return false;
        //}

        //public void Receive(Object o)
        //{
        //    if (o is YAMM.DataTypes.MovieDT)
        //    { }
        //}        

        //public event YAMM.PlugIn.DataEventHandler Send;        

        //public string Description
        //{
        //    get { return "k.A."; }
        //}


        ///// <summary>
        ///// Gets the icon of the plugin.
        ///// </summary>
        ///// <value>The icon.</value>
        //public System.Drawing.Image Icon
        //{
        //    get
        //    {
        //        return ((System.Drawing.Icon)global::PluginAmazon.Properties.Resources.ResourceManager.GetObject("Globe")).ToBitmap();
        //    }
        //}

        
        //void IPlugin.Load(IServiceProvider serviceProvider)
        //{
        //    IToolStripMenuManager menumanager = (IToolStripMenuManager)serviceProvider.GetService(typeof(IToolStripMenuManager));            
        //    throw new NotImplementedException();
        //}

        //void IPlugin.Unload()
        //{
        //    throw new NotImplementedException();
        //}
        
        //#endregion

        //public void Load(IServiceProvider serviceProvider)
        //{
        //    this.serviceProvider = serviceProvider;
        //    Main mn = new Main();
        //    mn.Show();
        //}

        IServiceProvider serviceProvider = null;
        #region IPlugin Members

        public string Name
        {
            get { return "AmazonPlugin"; }
        }

        public Guid Guid
        {
            get { return new Guid("5EF2E4A4-35A6-492c-A2C8-DF74F6F3D644"); }
        }

        public string Version
        {
            get { return ("0.0.1"); }
        }

        public string Author
        {
            get { return "Frank Weißenborn"; }
        }

        public string Description
        {
            get { return "Sucht einen eingegebenen Film bei Amazon"; }
        }

        public System.Drawing.Image Icon
        {
            //TODO
            get { return null; }
        }

        public void Configure()
        {
            Configure conf = new Configure();
            conf.ShowDialog();
        }

        public bool CanReceive(Type t)
        {
            throw new NotImplementedException();
        }

        public void Receive(object o)
        {
            throw new NotImplementedException();
        }

        public void Load(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;


            // create Browserwindow
            IWindowManager windowManager = serviceProvider.GetService(typeof(IWindowManager)) as IWindowManager;
            global::PluginAmazon.AmazonControl amazonCtrl = new AmazonControl();
            IWindow amazon = windowManager.Items.Add(Guid.NewGuid(), "Amazon Suche", amazonCtrl);
            amazon.Visible = false;
                       // create Menu
            IToolStripMenuManager menuManager = serviceProvider.GetService(typeof(IToolStripMenuManager)) as IToolStripMenuManager;
            
            // Button im MainMenu -> Extra
            IToolStripDropDownButton config = menuManager.Items[StandardIdentifiers.MainMenu].Items[StandardIdentifiers.MainMenuExtra] as IToolStripDropDownButton;
            IToolStripCheckableButton b =
                config.Items.AddCheckableButton(
                    Guid.NewGuid(),
                    "Amazon Suche",
                    delegate(object sender, EventArgs e)
                    {
                        if (((IToolStripCheckableButton)sender).Checked == true)
                        {
                            amazon.Visible = true;
                        }
                        else
                        {
                             amazon.Visible = false;
                        }
                    },
                    false,
                    Icon
                );

            // Menu verstecken wenn Browser nicht sichtbar
            amazon.Hidden +=
                delegate(object sender, EventArgs e)
                {
                    b.Checked = false;
                };
        }

        public void Unload()
        {
            throw new NotImplementedException();
        }

        public void Uninstall()
        {

        }

        public bool IsConfigureable()
        {
            return true;
        }

        public event DataEventHandler Send;

        #endregion
    }
}
